<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com> 
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * Music
 */
namespace Music\Controller;
use Music\Controller\PublicController;

/**
 *接口
 */
class MusicinterfaceController extends PublicController{
	
	/* 初始化 */
    protected function _initialize(){
		#header('Access-Control-Allow-Credentials:true');    //是否支持cookie跨域 
		#header('Access-Control-Allow-Origin: http://music.yanshi.zaiyoudao.com');//允许来源访问
		header('Access-Control-Allow-Origin: *');//允许来源访问
		header('Access-Control-Allow-Method:POST,GET,OPTIONS');//允许访问的方式     
		header("content-Type: text/html; charset=Utf-8"); 
	}
	
	/* 首页banner接口 */
	public function home_page_banner(){
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		if(IS_POST){
			#查询用户偏好
			$banner_str = '';
			$uid = I('param.uid');   //用户id
			if($uid > 0){
				$user_style_str = user_style($uid);
				
				#查询该偏好下的banner
				$banner_map['style_id'] = array('in',$user_style_str);
				$banner_map['style_table'] = 4;      //表示banner
				$banner_list = $m_cms_style->field('music_id')->where($banner_map)->select();
				
				#改为一维数组并且去重
				$banner_array = array_column($banner_list,'music_id');
				$banner_array = array_unique($banner_array);
				
				$banner_str = implode(',',$banner_array);
				
				#根据偏好查询出来的banner
				
				
			}
			if($banner_str != ''){
				$banner_str_map['id'] = array('in',$banner_str);
			}
			$banner_str_map['status'] = 1;
			$banner_str_map['form_id'] = 115;            //首页
			$banner_str_map['type'] = get_cms_model_conf('CMS_BANNER');
			$banner_str_list = $m_cms_content->where($banner_str_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit(5)->select();
			foreach($banner_str_list as $i=>$v){
				#$banner_str_list[$i]['img'] = "http://".$_SERVER['HTTP_HOST'].$banner_str_list[$i]['img'];
				$banner_str_list[$i]['img'] = if_url($banner_str_list[$i]['img']);
			}
			#总共5个banner图
			$banner_style_count = count($banner_str_list);
			
			#小于5时查询默认banner
			if($banner_style_count < 5){
				#查询剩下的默认banner图
				$banner_count = 5-$banner_style_count;
				
				$banner_cms_map['type'] = get_cms_model_conf('CMS_BANNER');
				$banner_cms_map['status'] = 1;
				$banner_cms_map['style_id'] = 0;
				$banner_cms_map['form_id'] = 115;            //首页
				$banner_cms_list = $m_cms_content->where($banner_cms_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit($banner_count)->select();
				foreach($banner_cms_list as $i=>$v){
					$banner_cms_list[$i]['img'] = if_url($banner_cms_list[$i]['img']);
				}
				foreach($banner_cms_list as $i=>$v){
					$banner_str_list[] = $banner_cms_list[$i];
				}
				
			}
			#img 图片 jump_type跳转类型(1活动页面，2专辑购买，3单曲试听)  jump_num 跳转页面id 
			
			
			#最终banner  $banner_str_list   排序后完成
			#排序
			$banner_str_list = banner_sorting($banner_str_list);
			
			$echo['error_code'] = 1;
			$echo['data'] = $banner_str_list;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
		
	}
	
	
	/* 首页专辑推荐接口 */
	public function home_page_tui(){
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$m_cms_style = M('cms_style');
		if(IS_POST){
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			
			$tuijian_str = '';
			if($uid > 0){
				$user_style_str = user_style($uid);
				#查询该偏好下的推荐专辑
				$tuijian_map['style_id'] = array('in',$user_style_str);
				$tuijian_map['style_table'] = 2;      //表示专辑
				$tuijian_list = $m_cms_style->field('music_id')->where($tuijian_map)->select();
				
				#改为一维数组并且去重
				$tuijian_array = array_column($tuijian_list,'music_id');
				$tuijian_array = array_unique($tuijian_array);
				
				$tuijian_str = implode(',',$tuijian_array);	
			}
			if($tuijian_str != ''){
				#根据偏好查询出来的专辑  
				$tuijian_str_map['id'] = array('in',$tuijian_str);
			}
			$tuijian_str_map['status'] = 1;
			$tuijian_str_map['recommended'] = 1;
			$tuijian_str_map['type'] = get_mall_model_conf('MALL_ALBUM');
			$tuijian_str_list = $m_mall_content->where($tuijian_str_map)->field("img,name,id")->order("sort desc")->limit(10)->select();
			foreach($tuijian_str_list as $i=>$v){
				$tuijian_str_list[$i]['img'] = if_url($tuijian_str_list[$i]['img']);
			}
			#查询该专辑下歌曲的数量
			foreach($tuijian_str_list as $i=>$v){
				$songs_map['form_id'] = $tuijian_str_list[$i]['id'];
				$songs_map['type'] = 17;
				$songs_map['status'] = 1;
				$tuijian_str_list[$i]['songs_count'] = $m_mall_content->where($songs_map)->count();
			}
			#img封面图  name名称  id主键    songs_count歌曲个数
			$echo['error_code'] = 1;
			$echo['data'] = $tuijian_str_list;
			#dump($echo);die;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
		
	}
	
	/* 专辑详情 */
	public function album_details(){
		$m_mall_content = M('mall_content');
		$m_cms_collection = M('cms_collection');
		$m_cms_content_comments = M('cms_content_comments');
		$m_mall_content_img = M('mall_content_img');
		$m_mall_content_music = M('mall_content_music');
		
		if(IS_POST){
			$id = I("param.id");
			$uid = I("param.uid")?I("param.uid"):0;
			#$id = 1087;
			$map['id'] = $id;
			$map['type'] = 16;
			$map['status'] = 1;
			$data = $m_mall_content->where($map)->field('id,name,banner_img,money,inventory,sale,isrc,intro')->find();
			$data['banner_img'] =  if_url($data['banner_img']);
			
			#判断是否购买
			$goumai_map['status'] = array("in",'1,2');
			$goumai_map['type'] = 22;
			$goumai_map['uid'] = $uid;
			$goumai_map['isrc'] = $data['isrc'];
			$goumai_data = $m_mall_content->where($goumai_map)->find();
			if($goumai_data){
				$data['if_goumai'] = 1;
			}else{
				$data['if_goumai'] = 0;
			}
			
			
			#收藏量
			$collection_map['type'] = 3;
			$collection_map['form_id'] = $id;
			$data['collection_count'] = $m_cms_collection->where($collection_map)->field("id")->count();
			
			#评论量
			$comments_map['type'] = 3;
			$comments_map['comments_id'] = $id;
			$comments_map['status'] = 1;
			$data['comments_count'] = $m_cms_content_comments->where($comments_map)->field("id")->count();
			
			#所有歌曲
			$song_map['form_id'] = $id;
			$song_map['type'] = 17;
			$song_map['status'] = 1;
			$all_song = $m_mall_content->where($song_map)->field("id,name,singer,value")->select();
			foreach($all_song as $i=>$v){
				#$all_song[$i]['mp3'] =  if_url($all_song[$i]['mp3']);
				$all_song[$i]['value'] =  if_url($all_song[$i]['value']);
				
				$img_map['type'] = 3;
				$img_map['form_id'] = $all_song[$i]['id'];
				$img_map['status'] = 1;
				$img_data = $m_mall_content_img->where($img_map)->order('employ desc')->find();
				$all_song[$i]['img'] = if_url($img_data['url']);
			}
			
			$data['all_song'] = $all_song;
			
			#试听歌曲
			$song = $m_mall_content->where($song_map)->field("id,name,singer,value")->order("sort desc")->find();
			#查询试听
			$song_map_s['form_id'] = $song['id'];
			$song_map_s['type'] = 5;
			$song_map_data = $m_mall_content_music->where($song_map_s)->find();
			
			$imgs_map['type'] = 3;
			$imgs_map['form_id'] = $song['id'];
			$imgs_map['status'] = 1;
			$song_data = $m_mall_content_img->where($imgs_map)->order('employ desc')->find();
			$song['mp3'] = if_url($song_map_data['url']);
			$song['value'] = if_url($song['value']);
			$song['img'] = if_url($song_data['url']);
			$data['song'][0] = $song;
			
			#判断是否喜欢
			$c_map['type'] = 3;
			$c_map['form_id'] = $id;
			$c_map['uid'] = $uid;
			$c_data = $m_cms_collection->where($c_map)->find();
			if($c_data){
				$data['if_like'] = 1;
			}else{
				$data['if_like'] = 0;
			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $data;
			
			#dump($echo);die;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
	}
	
	
	/* 专辑播放 */
	public function album_play(){
		$m_mall_content = M('mall_content');
		$m_cms_collection = M('cms_collection');
		$m_cms_content_comments = M('cms_content_comments');
		$m_mall_content_img = M('mall_content_img');
		
		if(IS_POST){
			$id = I("param.id");
			#$id = 1087;
			$map['id'] = $id;
			$map['type'] = 16;
			$map['status'] = 1;
			$data = $m_mall_content->where($map)->field('id,img,bottom_img,name,singer')->find();
			$data['img'] = if_url($data['img']);
			$data['bottom_img'] = if_url($data['bottom_img']);
			#前后各两张图  4张图
			$neiye_map['status'] = 1;
			$neiye_map['type'] = 4;
			$neiye_map['form_id'] = $data['id'];
			$neiye_data = $m_mall_content_img->where($neiye_map)->field("url")->order("sort desc")->select();
			foreach($neiye_data as $i=>$v){
				$neiye_data[$i]['url'] = if_url($neiye_data[$i]['url']);
			}
			$data['neiye'] = array_column($neiye_data,'url');
			
			#所有歌曲
			$song_map['form_id'] = $id;
			$song_map['type'] = 17;
			$song_map['status'] = 1;
			$all_song = $m_mall_content->where($song_map)->field("id,name,singer,mp3,value")->select();
			foreach($all_song as $i=>$v){
				$all_song[$i]['mp3'] =  if_url($all_song[$i]['mp3']);
				$all_song[$i]['value'] =  if_url($all_song[$i]['value']);
				#歌词底衬页
				$img_map['type'] = 2;
				$img_map['form_id'] = $all_song[$i]['id'];
				$img_map['status'] = 1;
				$img_data = $m_mall_content_img->where($img_map)->order('employ desc')->find();
				$all_song[$i]['foil_img'] = if_url($img_data['url']);
				#宣传页
				$img_map['type'] = 3;
				$img_map['form_id'] = $all_song[$i]['id'];
				$img_map['status'] = 1;
				$img_list = $m_mall_content_img->where($img_map)->field("url")->order('sort desc')->select();
				$img_list = array_column($img_list,'url');
				foreach($img_list as $ii=>$vv){
					$img_list[$ii] = if_url($img_list[$ii]);
				}
				$all_song[$i]['color_img'] = $img_list;
			}
			
			$data['all_song'] = $all_song;
			
			$echo['error_code'] = 1;
			$echo['data'] = $data;
			#dump($echo);die;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
	}
	
	
	
	/* 推荐活动接口 */
	public function tui_activity(){
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$m_cms_style = M('cms_style');
		if(IS_POST){
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			$activity_str = '';
			if($uid > 0){
				
				$user_style_str = user_style($uid);
				
				#查询该偏好下的活动
				$activity_map['style_id'] = array('in',$user_style_str);
				$activity_map['style_table'] = 3;      //表示专辑
				$activity_list = $m_cms_style->field('music_id')->where($activity_map)->select();
				//dump($user_style_str);die;
				#改为一维数组并且去重
				$activity_array = array_column($activity_list,'music_id');
				$activity_array = array_unique($activity_array);
				
				$activity_str = implode(',',$activity_array);
			}
			if($activity_str != ''){
				#根据偏好查询出来的专辑
				$activity_str_map['id'] = array('in',$activity_str);
			}
			$activity_str_map['status'] = 1;
			$activity_str_map['recommended'] = 1;
			$activity_str_map['type'] = 19;
			$activity_str_list = $m_mall_content->where($activity_str_map)->field("img,name,id,release_time,address,style")->order("sort desc")->select();
			
			foreach($activity_str_list as $i=>$v){
				$activity_str_list[$i]['img'] = if_url($activity_str_list[$i]['img']);
				$activity_str_list[$i]['style_name'] = style_str($activity_str_list[$i]['style']);
				$activity_str_list[$i]['time'] = date('Y-m-d H:i',$activity_str_list[$i]['release_time']);
				unset($activity_str_list[$i]['style']);
				unset($activity_str_list[$i]['release_time']);
			}
			#img封面图  name名称  id主键    time开始时间   address地点     style_name  风格   
			
			$echo['error_code'] = 1;
			$echo['data'] = $activity_str_list;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
	}
	/* PM精选活动接口 */
	public function jing_tui_activity(){
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$m_cms_style = M('cms_style');
		$m_mall_content_money = M('mall_content_money');
		if(IS_POST){
			#默认条数，页数
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):10;
			
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			$style = I('param.style');
			#$uid = 1;   //用户id
			$activity_str = '';
			if($uid > 0){
				
				$user_style_str = user_style($uid);
				
				#查询该偏好下的活动
				$activity_map['style_id'] = array('in',$user_style_str);
				$activity_map['style_table'] = 3;      //表示专辑
				$activity_list = $m_cms_style->field('music_id')->where($activity_map)->select();
				//dump($user_style_str);die;
				#改为一维数组并且去重
				$activity_array = array_column($activity_list,'music_id');
				$activity_array = array_unique($activity_array);
				
				$activity_str = implode(',',$activity_array);
				
			}
			if($activity_str != ''){
				
				#根据偏好查询出来的专辑
				$activity_str_map['id'] = array('in',$activity_str);
			}
			
			#传分类时使用分类
			if($style > 0){
				$activity_str_map['style'] = array('like',"%$style%");
				unset($activity_str_map['id']);
			}
			$activity_str_map['status'] = 1;
			$activity_str_map['recommended'] = 1;
			$activity_str_map['type'] = 19;
			$activity_str_list = $m_mall_content->where($activity_str_map)->field("img,name,id,release_time,address,style")->order("pm_sort desc")->page($p,$page)->select();
			
			foreach($activity_str_list as $i=>$v){
				$activity_str_list[$i]['img'] = if_url($activity_str_list[$i]['img']);
				$activity_str_list[$i]['style_name'] = style_str($activity_str_list[$i]['style']);
				$activity_str_list[$i]['time'] = date('Y-m-d H:i',$activity_str_list[$i]['release_time']);
				unset($activity_str_list[$i]['style']);
				unset($activity_str_list[$i]['release_time']);
				
				$time = time();
				$money_map['goods_id'] = $activity_str_list[$i]['id'];
				$money_map['begin_time'] = array("LT",time());
				$money_map['end_time'] = array("GT",time());
				$money_data = $m_mall_content_money->where($money_map)->field("goods_money")->find();
				$activity_str_list[$i]['money'] = $money_data['goods_money'];


			}
			#img封面图  name名称  id主键    time开始时间   address地点     style_name  风格   
			
			$echo['error_code'] = 1;
			$echo['data'] = $activity_str_list;
			#dump($echo);die;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
		
		
	}
	
	/* 专辑架 */
	public function my_album(){
		
		$m_mall_content = M("mall_content");
		if(IS_POST){
			$uid = I('param.uid');
			//$uid = 73;
			if($uid){
				
				#我创建的专辑
				$map['status'] = array('in','1,2,3,4,5');
				$map['type'] = get_mall_model_conf('MALL_ALBUM');
				$map['uid'] = $uid;
				$list = $m_mall_content->where($map)->order('time desc')->field("img,id,name,singer")->select();
				
				#我购买的专辑 
				$my_map['status'] = array('in','1,2');   //出售中  已出售
				$my_map['type'] = 22;
				$my_map['uid'] = $uid;
				$my_list = $m_mall_content->where($my_map)->order('time desc')->field("img,id,name,singer")->select();
				
				#合并两个数组
				$list = array_merge((array)$my_list,(array)$list);
				foreach($list as $i=>$v){
					$list[$i]['img'] = if_url($list[$i]['img']);
					$songs_map['form_id'] = $list[$i]['id'];
					$songs_map['type'] = 17;
					$songs_map['status'] = 1;
					$list[$i]['songs_count'] = $m_mall_content->where($songs_map)->count();
				}	
			}
			$echo['error_code'] = 1;
			$echo['data'] = $list;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
	}
	/* 专辑架 */    #915删除
	public function du_my_album(){
		
		$m_mall_content = M("mall_content");
		if(IS_POST){
			$uid = I('param.uid');
			//$uid = 73;
			if($uid){
				#我创建的专辑
				$map['status'] = array('in','1,2,3,4,5');
				$map['type'] = get_mall_model_conf('MALL_ALBUM');
				$map['uid'] = $uid;
				$list = $m_mall_content->where($map)->order('time desc')->field("img,id,name,singer")->select();
				
				#我购买的专辑 
				$my_map['status'] = array('in','1,2');   //出售中  已出售
				$my_map['type'] = 22;
				$my_map['uid'] = $uid;
				$my_list = $m_mall_content->where($my_map)->order('time desc')->field("img,id,name,singer")->select();
				
				#合并两个数组
				$list = array_merge((array)$my_list,(array)$list);
				foreach($list as $i=>$v){
					$list[$i]['img'] = if_url($list[$i]['img']);
					$songs_map['form_id'] = $list[$i]['id'];
					$songs_map['type'] = 17;
					$songs_map['status'] = 1;
					$list[$i]['songs_count'] = $m_mall_content->where($songs_map)->count();
				}
				
				$list_array = array_chunk($list,2);
				#dump($list_array);die;
			}
			
			
			$echo['error_code'] = 1;
			$echo['data'] = $list_array;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
	}
	
	/* 掏专辑中的banner */
	public function tao_banner(){
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		if(IS_POST){
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			if($uid){
				$user_style_str = user_style($uid);
				
				#查询该偏好下的banner
				$banner_map['style_id'] = array('in',$user_style_str);
				$banner_map['style_table'] = 4;      //表示banner
				$banner_list = $m_cms_style->field('music_id')->where($banner_map)->select();
				
				#改为一维数组并且去重
				$banner_array = array_column($banner_list,'music_id');
				$banner_array = array_unique($banner_array);
				
				$banner_str = implode(',',$banner_array);
				
				#根据偏好查询出来的banner
				
				$banner_str_map['id'] = array('in',$banner_str);
			}
			$banner_str_map['status'] = 1;
			$banner_str_map['form_id'] = 131;            //首页
			$banner_str_map['type'] = get_cms_model_conf('CMS_BANNER');
			$banner_str_list = $m_cms_content->where($banner_str_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit(5)->select();
			foreach($banner_str_list as $i=>$v){
					$banner_str_list[$i]['img'] = if_url($banner_str_list[$i]['img']);
				}
			#总共5个banner图
			$banner_style_count = count($banner_str_list);
			
			#小于5时查询默认banner
			if($banner_style_count < 5){
				#查询剩下的默认banner图
				$banner_count = 5-$banner_style_count;
				
				$banner_cms_map['type'] = get_cms_model_conf('CMS_BANNER');
				$banner_cms_map['status'] = 1;
				$banner_cms_map['style_id'] = 0;
				$banner_cms_map['form_id'] = 131;            //首页
				$banner_cms_list = $m_cms_content->where($banner_cms_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit($banner_count)->select();
				foreach($banner_cms_list as $i=>$v){
					$banner_cms_list[$i]['img'] = if_url($banner_cms_list[$i]['img']);
				}
				foreach($banner_cms_list as $i=>$v){
					$banner_str_list[] = $banner_cms_list[$i];
				}
				
			}
			#img 图片 jump_type跳转类型(1活动页面，2专辑购买，3单曲试听)  jump_num 跳转页面id 
			
			
			#最终banner  $banner_str_list   排序后完成
			#排序
			$banner_str_list = banner_sorting($banner_str_list);
			
			$echo['error_code'] = 1;
			$echo['data'] = $banner_str_list;
			
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	/* 掏专辑中的分类 */
	public function tao_tui_style(){
		$m_mall_content = M("mall_content");
		
		if(IS_POST){
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$list = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->select();
			foreach($list as $i=>$v){
				$list[$i]['img'] = if_url($list[$i]['img']);
			}
			$echo['error_code'] = 1;
			$echo['data'] = $list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
		
	}
	
	
	/* 掏专辑中的推荐专辑 */
	public function tao_tui_album(){
		
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		if(IS_POST){
			
			#第一个默认偏好风格
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$data = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->limit(1)->find();
			$data['img'] = if_url($data['img']);
			
			$style_id = I("param.style_id")?I("param.style_id"):$data['id'];
			
			#查询偏好风格下的专辑
			$tuijian_map['style_id'] = $style_id;
			$tuijian_map['style_table'] = 2;      //表示专辑
			$tuijian_list = $m_cms_style->field('music_id')->where($tuijian_map)->select();
			
			#改为一维数组并且去重
			$tuijian_array = array_column($tuijian_list,'music_id');
			$tuijian_array = array_unique($tuijian_array);
			
			$tuijian_str = implode(',',$tuijian_array);
			#该风格下的专辑
			$tuijian_str_map['id'] = array('in',$tuijian_str);
			$tuijian_str_map['status'] = 1;
			$tuijian_str_map['recommended'] = 1;
			$tuijian_str_map['type'] = get_mall_model_conf('MALL_ALBUM');
			$tuijian_str_list = $m_mall_content->where($tuijian_str_map)->field("img,name,id,inventory,sale,singer,money")->order("sort desc")->select();
			foreach($tuijian_str_list as $i=>$v){
				$tuijian_str_list[$i]['img'] = if_url($tuijian_str_list[$i]['img']);
				$tuijian_str_list[$i]['remaining'] = $tuijian_str_list[$i]['inventory'] - $tuijian_str_list[$i]['sale'];
				unset($tuijian_str_list[$i]['inventory']);
			}
			
			
			$echo['error_code'] = 1;
			$echo['data'] = $tuijian_str_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	
	/* 商城中的推荐活动 */
	public function tui_style(){
		$m_mall_content = M("mall_content");
		if(IS_POST){
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$list = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->select();
			foreach($list as $i=>$v){
				$list[$i]['img'] = if_url($list[$i]['img']);
			}
			$echo['error_code'] = 1;
			$echo['data'] = $list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	/* 活动中的推荐活动 */
	public function tui_style_activity(){
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		$m_mall_content_money = M("mall_content_money");
		if(IS_POST){
			
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):10;
			#第一个默认偏好风格
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$data = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->limit(1)->find();
			$data['img'] = if_url($data['img']);
			$style_id = I("param.style_id")?I("param.style_id"):$data['id'];
			
			#查询偏好风格下的专辑
			$tuijian_map['style_id'] = $style_id;
			$tuijian_map['style_table'] = 3;      //表示活动
			$tuijian_list = $m_cms_style->field('music_id')->where($tuijian_map)->select();
			
			#改为一维数组并且去重
			$tuijian_array = array_column($tuijian_list,'music_id');
			$tuijian_array = array_unique($tuijian_array);
			
			$tuijian_str = implode(',',$tuijian_array);
			#该风格下的专辑
			$tuijian_str_map['id'] = array('in',$tuijian_str);
			$tuijian_str_map['status'] = 1;
			$tuijian_str_map['recommended'] = 1;
			$tuijian_str_map['type'] = get_mall_model_conf('MALL_ACTIVITY');
			
			$activity_str_list = $m_mall_content->where($tuijian_str_map)->field("img,name,id,release_time,address,style")->page($p,$page)->order("sort desc")->select();
			
			foreach($activity_str_list as $i=>$v){
				$activity_str_list[$i]['img'] = if_url($activity_str_list[$i]['img']);
				$activity_str_list[$i]['style_name'] = style_str($activity_str_list[$i]['style']);
				$activity_str_list[$i]['time'] = date('Y-m-d H:i',$activity_str_list[$i]['release_time']);
				unset($activity_str_list[$i]['style']);
				unset($activity_str_list[$i]['release_time']);

				$time = time();
				$money_map['goods_id'] = $activity_str_list[$i]['id'];
				$money_map['begin_time'] = array("LT",time());
				$money_map['end_time'] = array("GT",time());
				$money_data = $m_mall_content_money->where($money_map)->field("goods_money")->find();
				$activity_str_list[$i]['money'] = $money_data['goods_money'];

			}
			#img封面图  name名称  id主键    time开始时间   address地点     style_name  风格   
			
			$echo['error_code'] = 1;
			$echo['data'] = $activity_str_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	/* 活动中 我参与的活动 */  
	public function tui_my_activity(){
		
		$m_mall_content = M("mall_content");
		$m_mall_order = M("mall_order");
		$m_cms_style = M("cms_style");
		if(IS_POST){
			$uid = I('param.uid');
			#$uid = 73;
			if($uid > 0){
				
				#查询我的所有商品id  
				$order_map['uid'] = $uid;
				$order_map['order_type'] = 3;
				$order_map['status'] = 1;
				$order_list = $m_mall_order->where($order_map)->field("id,goods_id")->order("time desc")->select();
				#改为一维数组并且去重
				$order_array = array_column($order_list,'goods_id');
				$order_array = array_unique($order_array);
				
				foreach($order_array as $i=>$v){
					$activity_map['id'] = $order_array[$i];
					$activity_data = $m_mall_content->where($activity_map)->field("name,release_time,address,style,img")->find();
					$activity_data['img'] = if_url($activity_data['img']);
					$activity_data['time'] = date("Y-m-d H:i",$activity_data['release_time']);
					$activity_data['style'] = style_str($activity_data['style']);
					$activity_data['order_id'] = $order_list[$i]['id'];
					$activity_list[] = $activity_data;
				}
				$echo['error_code'] = 1; 
				$echo['data'] = $activity_list; 
				#dump($echo);die;
				echo json_encode($echo);
			}
		}
		
	}
	
	/* 活动详情 */
	public function activity_details(){
		$m_mall_content = M("mall_content");
		$m_mall_content_money = M("mall_content_money");
		$m_cms_content_comments = M("cms_content_comments");
		$m_mall_content_img = M("mall_content_img");
		if(IS_POST){
			$id = I("param.id");
			#$id = 1269;
			if($id > 0){
				$map['id'] = $id;
				$map['type'] = get_mall_model_conf('MALL_ACTIVITY');
				$map['status'] = 1;
				$data = $m_mall_content->where($map)->field("img,name,style,release_time,address,url,value,id")->find();
				$yuming = "http://".$_SERVER['HTTP_HOST'].'/upload/';
				$data['value'] = str_ireplace('/upload/',$yuming,$data['value']);
				$data['banner_img'] = if_url($data['img']);
				$data['release_time'] = date("Y-m-d H:i",$data['release_time']);
				//var_dump($data);die;
				#风格 
				$data['style_name'] = style_str($data['style']);
				unset($data['style']);
				#价格
				$time = time();
				$money_map['goods_id'] = $id;
				$money_map['begin_time'] = array("LT",time());
				$money_map['end_time'] = array("GT",time());
				$money_data = $m_mall_content_money->where($money_map)->find();
				$data['money'] = $money_data['goods_money'];
				$data['goods_type_id'] = $money_data['id'];
				
				/* $url_array = explode(',',$data['url']);
				foreach($url_array as $i=>$v){
					$url_array[$i] = "http://".$_SERVER['HTTP_HOST'].$url_array[$i];
				} */
				#相册查询
				$img_map['type'] = 5;
				$img_map['form_id'] = $id;
				$img_map['status'] = 1;
				$url_list = $m_mall_content_img->where($img_map)->field("url")->select();
				foreach($url_list as $i=>$v){
					$old_imagename_name = strrchr($url_list[$i]['url'],"/");
					$old_imagename_name = substr($old_imagename_name,1);
					$url_jietu = "new_".$old_imagename_name;
					
					$xin_name = str_ireplace($old_imagename_name,$url_jietu,$url_list[$i]['url']);
					$url_list[$i]['jie_url'] = $xin_name;
				}
				$data['xiangce'] = $url_list;
				
				#改为一维数组并且去重
				#$url_array = array_column($url_list,'url');
				
				
				#评论数量
				$comments_map['comments_id'] = $id;
				$comments_map['status'] = 1;
				$data['count'] = $m_cms_content_comments->where($comments_map)->count();
				$echo['error_code'] = 1;
				$echo['data'] = $data;
				#dump($echo);die;
				$echo = json_encode($echo);
				echo $echo;
				#banner图  名称 票价  风格  日期  地点   相册  详情  评论数量
			}
		
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	/* 我的活动详情 */
	public function my_activity_details(){
		$m_mall_content = M("mall_content");
		$m_mall_order = M("mall_order");
		if(IS_POST){
			
			$order_id = I("param.order_id");
			#$order_id = 282;
			//$order_map['uid'] = $uid;
			#$order_map['order_type'] = 3;
			$order_map['status'] = 1;
			$order_map['id'] = $order_id;
			$order_data = $m_mall_order->where($order_map)->field("goods_time,goods_id")->find();
			
			$order_data['goods_time'] = if_url($order_data['goods_time']);
			#商品详情
			$goods_map['id'] = $order_data['goods_id'];
			$goods_data = $m_mall_content->where($goods_map)->field("name,style,release_time,address")->find();
			$goods_data['release_time'] = date("Y-m-d H:i",$goods_data['release_time']);
			$goods_data['style'] = style_str($goods_data['style']);
			$goods_data['goods_time'] = $order_data['goods_time'];
			$echo['error_code'] = 1;
			$echo['data'] = $goods_data;
			#dump($echo);
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] =0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	/* 账号注册 */
	public function registered(){
		$m_common_user = M("common_user");
		$m_sms_code = M("sms_code");
		//$data = I('');
		if(IS_POST){
			
			$code = I('param.code');
			$data['tel'] = I('param.tel');
			$code_map['name'] = $data['tel'];
			$code_map['code'] = $code;
			$code_map['status'] = 2;
			$code_data = $m_sms_code->where($code_map)->find();
			 $user_name = $m_common_user->where($data)->find();
			 if(!$user_name){
				if($code_data){
					#验证码正确
					$saves['status'] = 1;
					$m_sms_code->where($code_map)->save($saves);
					$data['username'] = $data['tel'];
					$data['password'] = md5(I('param.password'));
					$data['img'] = "http://".$_SERVER['HTTP_HOST']."upload/1/2018/05/16/5afc078974b97.gif";
					$data['create_time'] = time();
					$data['create_ip'] = get_client_ip();
					$data['group_id'] = 3; //默认群组TODO动态配置
					$data['status'] = 1;
					$result = $m_common_user->add($data);
					$info = $result;
				}else{
					$info = -1;
				}
			 }else{
				 $info = -3;
			 }
		}else{
			$info = -2;
		}
		$echo['error_code'] = $info;
		#大于0表示注册登陆成功，返回值为id  -1表示验证码错误  -2请求错误  -3表示已经注册
		echo json_encode($echo);
	}
	
	/* 手机号验证  注册 */
	public function phone_validation(){
		$m_common_user = M("common_user");
		$m_sms_code = M("sms_code");
		if(IS_POST){
			$tel = I("param.tel");
			$map['username'] = $tel;
			$map['status'] = 1;
			$user_data = $m_common_user->where($map)->find();
			if(!$user_data){
				
				$code = mt_rand(1000,9999);
				smsbao_send($tel,$code);
				
				$add_code['name'] = $tel;
				$add_code['code'] = $code;
				$add_code['time'] = time();
				$add_code['status'] = 2;
				$add_result = $m_sms_code->add($add_code);
				
				if($add_result){
					$info = 1;    //发送成功
				}else{
					$info = 0;      //发送失败
				}
			}else{
				$info = -2;     //用户已注册
			}
		}
		//$info['error_code'] = $info;
		$echo['error_code'] = $info;
		echo json_encode($echo);
			
	}
	
	/* 手机号登陆验证 */
	public function phone_validations(){
		$m_common_user = M("common_user");
		$m_sms_code = M("sms_code");
		if(IS_POST){
			$tel = I("param.tel");
			$map['username'] = $tel;
			$map['status'] = 1;
			$user_data = $m_common_user->where($map)->find();
			if($user_data){
				
				$code = mt_rand(1000,9999);
				smsbao_send($tel,$code);
				
				$add_code['name'] = $tel;
				$add_code['code'] = $code;
				$add_code['time'] = time();
				$add_code['status'] = 2;
				$add_result = $m_sms_code->add($add_code);
				
				if($add_result){
					$info = 1;    //发送成功
				}else{
					$info = 0;      //发送失败
				}
			}else{
				$info = -2;     //用户未注册
			}
		}else{
			$info = -3;
		}
		//$info['error_code'] = $info;
		
		$echo['error_code'] = $info;
		echo json_encode($echo);
			
	}
	
	/* 手机短信登陆 */
	public function phone_denglu(){
		$m_common_user = M("common_user");
		$m_sms_code = M("sms_code");
		if(IS_POST){
			$tel = I("param.tel");
			$code = I("param.code");
			$map['username'] = $tel;
			#$map['status'] = 1;
			$user_data = $m_common_user->where($map)->find();
			if($user_data['status'] == 1){
				$code_map['name'] = $tel;
				$code_map['code'] = $code;
				$code_map['status'] = 2;
				$code_data = $m_sms_code->where($code_map)->find();
				if($user_data['group_id'] == 9){
					$if_yyr = 1;
				}
				if($code_data){
					$save_data['status'] = 1;
					$m_sms_code->where($code_map)->save($save_data);
					
					$info = $user_data['id'];
				}else{
					$info = -1; //验证码错误
				}
				
			}elseif($user_data['status'] > 1){
					$info = -3;    //账号被封
			}else{
				$info = -2;     //用户不存在
			}
		}
		//$info['error_code'] = $info;
		$echo['error_code'] = $info;
		$echo['if_yyr'] = $if_yyr;
		echo json_encode($echo);
			
	}
	
	
	/* 图文验证 */
	public function Verifys(){
	
		$Verify = new \Think\Verify();
		// 设置验证码字符为纯数字 
		$Verify->codeSet = '0123456789';
		$img = $Verify->entry($id);
		return $img;
		#dump($_SESSION);die;
	}
	
	/* 图文验证 */
	public function Verifys_url(){
		$p = rand(1,1000);
		echo "http://".$_SERVER['HTTP_HOST']."/music/Musicinterface/Verifys/p/".$p;
	}
	
	/* 登陆 */
	public function login(){
		$m_common_user = M("common_user");
		$if_yyr = 0;
		/* if(IS_POST){ */
			#图文验证
			$code = I("param.code");
			$password = I('param.password');
			$id = I("param.id")?I("param.id"):'';
			
			$verify = new \Think\Verify();
			$id = I("param.id")?I("param.id"):'';
			$results = $verify->check($code, $id);
			/* $results = verifys_yanzheng($code); */
			if($results){ 
				$map['tel | username'] = I('param.username');
				$map['password'] = md5($password);
				$map['status'] = 1;
				$result = $m_common_user->where($map)->field('id')->find();
				
				if($result['id'] > 0){
					$info = $result['id'];
					if($result['group_id'] == 9){
						$if_yyr = 1;
					}
				}else{
					$info = -1;     //用户名或密码不对
				}
			}else{
				$info = -3;    //验证码错误 
			}
		/* }else{
			$info = -2;         //
		} */
		$echo['error_code'] = $info;
		$echo['if_yyr'] = $if_yyr;
		echo json_encode($echo);
		
		
	}
	
	/* 偏好修改 */
	public function save_style(){
		$m_cms_style = M("cms_style");
		$map['music_id'] = I('param.uid');
		$map['style_table'] = 5;
		if(IS_POST){
			
			$style = I('param.style');
			$style_array = explode(',',$style);
			$m_cms_style->where($map)->delete();
			foreach($style_array as $i=>$v){
				$map['style_id'] = $style_array[$i];
				$result = $m_cms_style->add($map);
			}
			$info = 1;
		}else{
			$info = -1;
		}
		$echo['error_code'] = $info;
		echo json_encode($echo);
	}
	
	/* 音乐人排序 */
	public function tui_music_people(){
		$m_common_user = M("common_user");
		if(IS_POST){
			$map['recommended']  = 1;
			$map['group_id']  = 9;
			$map['status']  = 1;
			$list = $m_common_user->where($map)->order('sort desc')->select();
			
			$echo['error_code'] = 1;
			$echo['data'] = $list;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	/* 我喜欢中随机推荐单曲  猜你喜欢 */
	public function random_like_song(){
		
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		$m_mall_content = M('mall_content');   //banner
		$m_mall_content_img = M('mall_content_img');   //banner
		$m_mall_content_music = M('mall_content_music');   //banner
		$m_cms_content_comments = M('cms_content_comments');   //banner
		$m_cms_collection = M('cms_collection');   //banner
		if(IS_POST){
			
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0){
				$user_style_str = user_style($uid);
				#随机查询该偏好下的歌曲
				$song_map['style_id'] = array('in',$user_style_str);
				$song_map['style_table'] = 1;      //表示单曲
				$song_list = $m_cms_style->field('music_id')->where($song_map)->select();
				
				#改为一维数组并且去重
				$song_array = array_column($song_list,'music_id');
				$song_array = array_unique($song_array);
				$song_str = implode(',',$song_array);
				
				#根据偏好查询出来的歌曲
				$song_str_map['id'] = array('in',$song_str);
			}
			#dump($user_style_str);die;
			$song_str_map['status'] = 1;
			$song_str_map['recommended'] = 1;
			$song_str_map['type'] = get_mall_model_conf('MALL_SINGLE');
			$song_str_list = $m_mall_content->where($song_str_map)->field("id")->limit(100)->select();
			$song_str_list = array_column($song_str_list,'id');
			
			shuffle($song_str_list);
			$song_str_list = array_slice($song_str_list, 0, 9); 
			$song_str_array = song_detail($song_str_list,$uid);
			
			$echo['error_code'] = 1;
			$echo['data'] = $song_str_array;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	/* 单曲播放随即选歌 */
	public function suiji_song(){
		
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		$m_mall_content = M('mall_content');   //banner
		$m_mall_content_img = M('mall_content_img');   //banner
		if(IS_POST){
				#第一个默认偏好风格
				$map['type'] = get_mall_model_conf('MALL_STYLE');
				$map['status'] = 1;
				$data = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->limit(1)->find();
				
				$user_style_str = I("param.style_id")?I("param.style_id"):$data['id'];
				#随机查询该偏好下的歌曲
				$song_map['style_id'] = array('in',$user_style_str);
				$song_map['style_table'] = 1;      //表示单曲
				$song_list = $m_cms_style->field('music_id')->where($song_map)->select();
				
				#改为一维数组并且去重
				$song_array = array_column($song_list,'music_id');
				$song_array = array_unique($song_array);
				$song_str = implode(',',$song_array);
				
				#根据偏好查询出来的歌曲
				$song_str_map['id'] = array('in',$song_str);
			
			$song_str_map['status'] = 1;
			$song_str_map['recommended'] = 1;
			$song_str_map['type'] = get_mall_model_conf('MALL_SINGLE');
			$song_str_list = $m_mall_content->where($song_str_map)->field("id")->limit(100)->select();
			$song_str_list = array_column($song_str_list,'id');
			shuffle($song_str_list);
			$song_str_list = array_slice($song_str_list, 0, 20); 
			foreach($song_str_list as $i=>$v){
				$song_map_t['id'] = $song_str_list[$i];
				$song_str_array = song_detail($song_str_list);
				/* $song_str_data = $m_mall_content->where($song_map_t)->field("id,name,singer")->find();
				$xuanze_img_map['type'] = 1;					
				$xuanze_img_map['form_id'] = $song_str_list[$i];
				$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
				$song_str_data['img'] = if_url($xuanze_img_data['url']);
				$song_str_list[$i] = $song_str_data; */
			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $song_str_array;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	/* 我喜欢的单曲 */
	function my_like_song(){
		$m_cms_collection = M("cms_collection");
		$m_mall_content = M("mall_content");
		$m_mall_content_img = M("mall_content_img");
		if(IS_POST){
			
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):10;
			
			$uid = I('param.uid')?I('param.uid'):0;   //用户id
			if($uid > 0){
				$map['uid'] = $uid;
				$map['type'] = 1;
				$list = $m_cms_collection->where($map)->field('form_id')->page($p,$page)->select();
				$list_list = array_column($list,'form_id');
				
				$list_list = array_unique($list_list);
				
				$song_array = song_detail($list_list,$uid);
				
				
				/* $song_array = array();
				
				foreach($list_list as $i=>$v){
					$song_map['id'] = $list_list[$i];
					$song_map['type'] = 15;
					$song_map['status'] = 1;
					$song_data = $m_mall_content->where($song_map)->field("id,name,singer,mp3,foil_img,value")->find();
					
					#判断是否是独家以及是否是超品
					$hq_dujia_array = if_hq_dujia($list_list[$i]);
					$song_data['if_hq'] = $hq_dujia_array['if_hq'];
					$song_data['if_dujia'] = $hq_dujia_array['if_dujia'];
					
					
					$song_data['mp3'] = if_url($song_data['mp3']);
					$song_data['foil_img'] = if_url($song_data['foil_img']);
					$song_data['value'] = if_url($song_data['value']);
					if($song_data){
						$xuanze_img_map['type'] = 1;					
						$xuanze_img_map['form_id'] = $list_list[$i];
						$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
						$song_data['img'] = if_url($xuanze_img_data['url']);
						$song_array[] = $song_data;
					}
				} */
				$echo['error_code'] = 1;
				$echo['data'] = $song_array;
				#dump($echo);die;
				echo json_encode($echo);die;
				
			}else{
				
				$echo['error_code'] = 1;
				$echo['data'] = array();
				echo json_encode($echo);die;
			}
		
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);die;
		}
	}
	
	/* 我喜欢的专辑 */
	function my_like_album(){
		$m_cms_collection = M("cms_collection");
		$m_mall_content = M("mall_content");
		$m_mall_content_img = M("mall_content_img");
		if(IS_POST){
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0){
				$map['uid'] = $uid;
				$map['type'] = 3;
				$list = $m_cms_collection->where($map)->field('form_id')->select();
				$list_list = array_column($list,'form_id');
				$list_list = array_unique($list_list);
				$song_array = array();
				foreach($list_list as $i=>$v){
					$song_map['id'] = $list_list[$i];
					$song_map['type'] = 16;
					$song_map['status'] = 1;
					$song_data = $m_mall_content->where($song_map)->field("id,name,singer,img")->find();
					$song_data['img'] = if_url($song_data['img']);
					$song_array[] = $song_data;
				}
			}else{
				$song_array = array();
			}
			$echo['error_code'] = 1;
			$echo['data'] = $song_array;
			#dump($echo);die;
			echo json_encode($echo);die;
		
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);die;
		}
	}
	
	
	/* 我喜欢中随机推荐音乐人 */
	public function random_like_artists(){
		
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		$m_mall_content = M('mall_content');   //banner
		$m_mall_content_img = M('mall_content_img');   //banner
		$m_cms_collection = M('cms_collection');   //banner
		if(IS_POST){
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):10;
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0){
				$user_style_str = user_style($uid);
				
				#随机查询该偏好下的歌曲
				$artists_map['style_id'] = array('in',$user_style_str);
				$artists_map['style_table'] = 5;      //表示用户
				$artists_list = $m_cms_style->field('music_id')->where($artists_map)->select();
				
				#改为一维数组并且去重
				$artists_array = array_column($artists_list,'music_id');
				$artists_array = array_unique($artists_array);
				$artists_str = implode(',',$artists_array);
				
				#根据偏好查询出来的歌曲
				$artists_str_map['id'] = array('in',$artists_str);
				
			}
			$artists_str_map['status'] = 1;
			$artists_str_map['group_id'] = 9;
			$artists_str_list = $m_common_user->where($artists_str_map)->field("id,name,img")->limit(100)->select();
			
			shuffle($artists_str_list);
			$artists_str_list = array_slice($artists_str_list, 0, 10);
			
			#dump($artists_str_list);die;
			#查询粉丝量
			foreach($artists_str_list as $i=>$v){
				#判断是否是授权   授权的头像了路径不改变
				
				$artists_str_list[$i]['img'] = if_url($artists_str_list[$i]['img']);
				
				$fensi_map['form_id'] = $artists_str_list[$i]['id'];
				$fensi_map['type'] = 2;
				$artists_str_list[$i]['count'] = $m_cms_collection->where($fensi_map)->field("id")->count();
				
				#判断是否喜欢
				$if_map['uid'] = $uid;
				$if_map['form_id'] = $artists_str_list[$i]['id'];
				$if_map['type'] = 2;
				$if_data = $m_cms_collection->where($if_map)->field("id")->find();
				if($if_data){
					$artists_str_list[$i]['if_like'] = 1;
				}else{
					$artists_str_list[$i]['if_like'] = 0;
				}
				
				
			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $artists_str_list;
			#dump($echo);die;
			echo json_encode($echo);
			
		 }else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	/* 我关注的音乐人 */
	function my_like_artists(){
		$m_cms_collection = M("cms_collection");
		$m_mall_content = M("mall_content");
		$m_mall_content_img = M("mall_content_img");
		$m_common_user = M("common_user");
		if(IS_POST){
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0){
				$map['uid'] = $uid;
				$map['type'] = 2;
				$list = $m_cms_collection->where($map)->field('form_id')->select();
				$list_list = array_column($list,'form_id');
				$list_list = array_unique($list_list);
				$artists_array = array();
				//dump($list_list);die;
				foreach($list_list as $i=>$v){
					$artists_map['id'] = $list_list[$i];
					$artists_map['group_id'] = 9;
					$artists_map['status'] = 1;
					$artists_data = $m_common_user->where($artists_map)->field("id,name,img,fans")->find();
					if($artists_data){
						#判断是否是授权   授权的头像了路径不改变
						$artists_data['img'] = if_url($artists_data['img']);
						
						#查询粉丝量
						/* $fensi_map['form_id'] = $artists_str_list[$i]['id'];
						$fensi_map['type'] = 2;
						$artists_data['count'] = $m_cms_collection->where($fensi_map)->field("id")->count(); */
						
						$artists_data['count']  = $artists_data['fans'] ;
						#判断是否关注
						$artists_data['if_like_user'] = if_like_user($list_list[$i],$uid);
						$artists_array[] = $artists_data;
					}
					
				}
				
				$echo['error_code'] = 1;
				$echo['data'] = $artists_array;
				#dump($echo);die;
				echo json_encode($echo);die;
			}else{
				$echo['error_code'] = 1;
				echo json_encode($echo);die;
			}
		
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);die;
		}
	}
	
	/* 我喜欢中随机推荐专辑 */
	public function random_like_album(){
		
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		$m_mall_content = M('mall_content');   //banner
		$m_mall_content_img = M('mall_content_img');   //banner
		if(IS_POST){
			
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0){
				$user_style_str = user_style($uid);
				//dump($user_style_str);die;
				#随机查询该偏好下的歌曲
				$song_map['style_id'] = array('in',$user_style_str);
				$song_map['style_table'] = 2;      //表示单曲
				$song_list = $m_cms_style->field('music_id')->where($song_map)->select();
				
				#改为一维数组并且去重
				$song_array = array_column($song_list,'music_id');
				$song_array = array_unique($song_array);
				$song_str = implode(',',$song_array);
				
				#根据偏好查询出来的歌曲
				$song_str_map['id'] = array('in',$song_str);
			}
			$song_str_map['status'] = 1;
			$song_str_map['recommended'] = 1;
			$song_str_map['type'] = get_mall_model_conf('MALL_ALBUM');
			$song_str_list = $m_mall_content->where($song_str_map)->field("id")->limit(100)->select();
			$song_str_list = array_column($song_str_list,'id');
			shuffle($song_str_list);
			$song_str_list = array_slice($song_str_list, 0, 9); 
			foreach($song_str_list as $i=>$v){
				$song_map_t['id'] = $song_str_list[$i];
				$song_str_data = $m_mall_content->where($song_map_t)->field("id,name,singer,img")->find();
				
				$song_str_data['img'] = if_url($song_str_data['img']);
				$song_str_list[$i] = $song_str_data;
			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $song_str_list;
			//dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	/* 我喜欢中随机推荐活动 */
	public function random_like_activity(){
		
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		$m_mall_content = M('mall_content');   //banner
		$m_mall_content_img = M('mall_content_img');   //banner
		$m_mall_content_money = M('mall_content_money');   //banner
		if(IS_POST){
			
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0){
				$user_style_str = user_style($uid);
				#随机查询该偏好下的歌曲
				$song_map['style_id'] = array('in',$user_style_str);
				$song_map['style_table'] = 3;      //表示活动
				$song_list = $m_cms_style->field('music_id')->where($song_map)->select();
				
				#改为一维数组并且去重
				$song_array = array_column($song_list,'music_id');
				$song_array = array_unique($song_array);
				$song_str = implode(',',$song_array);
				
				#根据偏好查询出来的歌曲
				$song_str_map['id'] = array('in',$song_str);
			}
			$song_str_map['status'] = 1;
			$song_str_map['recommended'] = 1;
			$song_str_map['type'] = get_mall_model_conf('MALL_ACTIVITY');
			$song_str_list = $m_mall_content->where($song_str_map)->field("id")->limit(100)->select();
			$song_str_list = array_column($song_str_list,'id');
			shuffle($song_str_list);
			
			$song_str_list = array_slice($song_str_list, 0, 9); 
			foreach($song_str_list as $i=>$v){
				$song_map_t['id'] = $song_str_list[$i];
				$song_str_data = $m_mall_content->where($song_map_t)->field("img,name,id,release_time,address,style")->find();
				$song_str_data['style'] = style_str($song_str_data['style']);
				$song_str_data['img'] = if_url($song_str_data['img']);
				$song_str_data['release_time'] = date("Y-m-d H:i",$song_str_data['release_time']);

				$time = time();
				$money_map['goods_id'] = $song_str_list[$i]['id'];
				$money_map['begin_time'] = array("LT",time());
				$money_map['end_time'] = array("GT",time());
				$money_data = $m_mall_content_money->where($money_map)->field("goods_money")->find();
				$song_str_list[$i]['money'] = $money_data['goods_money'];


				$song_str_list[$i] = $song_str_data;

			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $song_str_list;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	
	/* 单曲播放 */
	#id  name 名称  singer 歌手  foil_img 歌词低衬页  value 歌词  if_like  是否喜欢  c_count 评论数量
	public function song_play(){
		$m_mall_content = M('mall_content');
		$m_cms_content_comments = M('cms_content_comments');
		$m_cms_collection = M("cms_collection");
		$m_cms_recently = M("cms_recently");
		$m_cms_recentlys = M("cms_recentlys");
		if(IS_POST){
			$uid = I("param.uid");
			$map['id'] = I('param.id');
			if($map['id'] > 0){
				#存取历史记录
				$jilu_map['type'] = 2;
				$jilu_map['r_id'] = $map['id'];
				$jilu_map['uid'] = $uid;
				$jilu_data = $m_cms_recently->where($jilu_map)->find();
				if($jilu_data){
					$jilu_save['count'] = $jilu_data['count'] + 1;
					$jilu_save['time'] = time();
					$jilu_save['status'] = 1;
					$m_cms_recently->where($jilu_map)->save($jilu_save);
				}else{
					$jilu_save['type'] = 2;
					$jilu_save['r_id'] = $map['id'];
					$jilu_save['uid'] = $uid;
					$jilu_save['count'] = 1;
					$jilu_save['time'] = time();
					$jilu_save['status'] = 1;
					$m_cms_recently->add($jilu_save);
				}
				$add['type'] = 2;
				$add['r_id'] = $map['id'];
				$add['uid'] = $uid;
				$add['time'] = time();
				$m_cms_recentlys->add($add);
				
				$map['status'] = 1;
				$map['type'] = 15;
				$data = $m_mall_content->where($map)->field('id,name,singer,foil_img,value,mp3')->find();
				$data['foil_img'] = if_url($data['foil_img']);
				$data['value'] = if_url($data['value']);
				$data['mp3'] = if_url($data['mp3']);
				$data['value_text'] = file_get_contents($data['value']);//将整个文件内容读入到一个字符串中
				#评论数量
				$comments_map['form_id'] = $map['id'];
				$comments_map['type'] = 2;
				$comments_map['status'] = 1;
				$data['c_count'] = $m_cms_content_comments->where($comments_map)->count();
				#是否喜欢
				$cc_map['type'] = 1;
				$cc_map['form_id'] = $map['id'];
				$cc_map['uid'] = $uid;
				$cc_data = $m_cms_collection->where($cc_map)->find();
				if($cc_data){
					$data['if_like'] = 1;
				}else{
					$data['if_like'] = 0;
				}
				#四个品质链接
				$data['gedan_list'] = gedan_list($data['id']);
				
			}else{
				$data = array();
			}
			$echo['error_code'] = 1;
			$echo['data'] = $data;
			/* dump($cc_data);
			dump($echo);
			die; */
			echo json_encode($echo);
		
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	/* 最近浏览过的专辑 */
	public function recently_album(){
		$m_cms_recently = M("cms_recently");
		$m_mall_content = M("mall_content");
		if(IS_POST){
			
			$map['type'] = 1;    //专辑
			$map['uid'] = I('param.uid');
			$map['uid'] = 1;
			$list = $m_cms_recently->where($map)->field("r_id")->order("time desc")->limit(6)->select();
			$list = array_column($list,'r_id');
			$list = array_unique($list);
			
			foreach($list as $i=>$v){
				
				$a_map['id'] = $list[$i];
				$a_map['status'] = 1;
				$a_map['type'] = get_mall_model_conf('MALL_ALBUM');
				$data = $m_mall_content->where($a_map)->field("img,name,id")->order("sort desc")->find();
				$data['img'] = if_url($data['img']);
				$songs_map['form_id'] = $list[$i];
				$songs_map['type'] = 17;
				$songs_map['status'] = 1;
				$data['songs_count'] = $m_mall_content->where($songs_map)->count();
				
				$data_array[] = $data;
			}
			$echo['error_code'] = 1;
			$echo['data'] = $data_array;
			
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
			
		}
	}
	
	/* 最近浏览过的音乐人 */
	#id   nickname昵称    img 头像   count 粉丝数量 
	public function recently_music_people(){
		$m_cms_recently = M("cms_recently");
		$m_common_user = M("common_user");
		$m_cms_collection = M("cms_collection");
		if(IS_POST){
		
			$map['type'] = 4;   //音乐人
			$map['uid'] = I('param.uid');
			$list = $m_cms_recently->where($map)->field("r_id")->order("time desc")->limit(3)->select();
			$list = array_column($list,'r_id');
			$list = array_unique($list);
			
			foreach($list as $i=>$v){
				$u_map['group_id'] = 9;
				$u_map['status'] = 1;
				$u_map['id'] = $list[$i];
				$u_data = $m_common_user->where($u_map)->field("id,nickname,img")->find();
				#判断是否是授权   授权的头像了路径不改变
				$u_data['img'] = if_url($u_data['img'] );
				$fensi_map['form_id'] = $list[$i];
				$fensi_map['type'] = 2;
				$u_data['count'] = $m_cms_collection->where($fensi_map)->field("id")->count();
				
				$data_array[] = $u_data;
			}
			$echo['error_code'] = 1;
			$echo['data'] = $data_array;
			#dump($echo);die;
			echo json_encode($echo);
			
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
		
	}
	
	
	/* 浏览过的活动  */
	public function recently_activity(){
		$m_cms_recently = M("cms_recently");
		$m_mall_content = M("mall_content");
		$m_mall_content_money = M("mall_content_money");

		if(IS_POST){
			$map['type'] = 3;   //活动 
			$map['uid'] = I('param.uid');
			$map['uid'] = 1;
			$list = $m_cms_recently->where($map)->field("r_id")->order("time desc")->limit(2)->select();
			$list = array_column($list,'r_id');
			$list = array_unique($list);
			
			foreach($list as $i=>$v){
				$tuijian_str_map['id'] = $list[$i];
				$tuijian_str_map['status'] = 1;
				$tuijian_str_map['type'] = get_mall_model_conf('MALL_ACTIVITY');
				$activity_str_list = $m_mall_content->where($tuijian_str_map)->field("img,name,id,release_time,address,style")->find();
				$activity_str_list['img'] = if_url($activity_str_list['img']);
				$activity_str_list['style_name'] = style_str($activity_str_list['style']);
				$activity_str_list['time'] = date('Y-m-d H:i',$activity_str_list['release_time']);
				unset($activity_str_list['style']);
				unset($activity_str_list['release_time']);
				$time = time();
				$money_map['goods_id'] = $activity_str_list[$i]['id'];
				$money_map['begin_time'] = array("LT",time());
				$money_map['end_time'] = array("GT",time());
				$money_data = $m_mall_content_money->where($money_map)->field("goods_money")->find();
				$activity_str_list[$i]['money'] = $money_data['goods_money'];
				$data_array[] = $activity_str_list;
			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $data_array;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	/* 浏览过的单曲  */
	public function recently_song(){
		$m_cms_recently = M("cms_recently");
		$m_mall_content = M("mall_content");
		$m_mall_content_img = M("mall_content_img");
		
		if(IS_POST){
			$map['type'] = 2;   //单曲  
			$map['uid'] = I('param.uid');
			#$map['uid'] = 1;
			$list = $m_cms_recently->where($map)->field("r_id")->order("time desc")->limit(4)->select();
			$list = array_column($list,'r_id');
			$list = array_unique($list);
			#dump($list);die;
			/* foreach($list as $i=>$v){
				$song_map_t['id'] = $list[$i];
				$song_map_t['type'] = 15;
				$song_map_t['status'] = 1;
				$song_str_data = $m_mall_content->where($song_map_t)->field("id,name,singer")->find();
				if($song_str_data){
					$xuanze_img_map['type'] = 1;					
					$xuanze_img_map['form_id'] = $list[$i];
					$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
					$song_str_data['img'] = if_url($xuanze_img_data['url']);
				}
				$data_array[] = $song_str_data;
			} */
			$data_array = song_detail($list,$map['uid']);
			//dump($data_array);die;
			$echo['error_code'] = 1;
			$echo['data'] = $data_array;
			#dump($echo);die;
			echo json_encode($echo);
			
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
}